var hasInitList = false;
var curFocusId = 1;
var curLeftId = 0;
var disNum = 7;
var itemWidth = 150;
function showList(){
	if(!dataList ||  dataList.length == 0){ return ;}
	
	if(!hasInitList){
		initList();
	}
	$('#ulBox').show();
	$('#li-a-'+curFocusId).focus();
}

function hideList(){
	$('#justForA').focus();
	 KEY.CURTYPE = false;
	 $('#ulBox').hide();
}

function initList(){
	var con = '',data,j;
	for(var i = 0 ;i<dataList.length;i++){
		j = i + 1;
		data = dataList[i];
		var img = $.getImageUrl(data.img,DEFAULT_IMG);
		con += '<a href="#" id="li-a-'+j+'"><img src="'+img+'"/></a>';
	}
	$('#listBox').html(con);
	$('#listBox a').focus(function(e) {
		 var idArr = this.id.split('-');
		 var tar = parseInt(idArr[2]);
		var data = dataList[tar - 1];
		$('#ulBox .title').html(data.title);
		$.log(curFocusId + ':'+tar);
		if(curFocusId > tar){			//向左
			if(tar - curLeftId == 1 && tar!= 1){
				curLeftId --;
				$('#listBox').animate({"left":-curLeftId*itemWidth});
			}
		}else if(curFocusId < tar){		//向右
			if(tar - curLeftId  == disNum && tar != dataList.length){
				curLeftId ++ ;
				$('#listBox').animate({"left":-curLeftId*itemWidth});
			}
		}
		 curFocusId = tar;
		 
		 if(curLeftId > 0){
			 $('#toLeft').show();
		}else{
			$('#toLeft').hide();
		}
		if(curLeftId + disNum < dataList.length){
			 $('#toRight').show();
		}else{
			$('#toRight').hide();
		}
		 
         KEY.CURTYPE = 'ulbox';
    }).click(function(e) {
        var idArr = this.id.split('-');
		var tar = parseInt(idArr[2]);
		var data = dataList[tar - 1];
		curItemId = tar;
		hideList();
		play(data);
    });;
}

KEY.TYPE['ulbox'] = function(key,keyName,a){
	var idArr = a.id.split('-');
	var tar = parseInt(idArr[2]);
	var bo = $('#listBox').is(":animated");
	if(bo) return ;
	
	if(keyName == 'KEY_RETURN'){
		hideList();
	}else if(keyName == 'KEY_RIGHT'){
		tar ++;
		if(tar <=dataList.length){
			$('#li-a-'+tar).focus();
		}
	}else if(keyName == 'KEY_LEFT'){
		tar --;
		if(tar >0){
			$('#li-a-'+tar).focus();
		}
	}
}